namespace SilverSea.LPRProcessing
{
    using System;

    public class PlateNumberFixing
    {
        private bool bool_0;
        private PlateFeatures plateFeatures_0 = PlateFeatures.Both;
        private string string_0 = "VN";
        private string string_1 = string.Empty;

        public string Fix(string plateNumber)
        {
            if (plateNumber[0] == '0')
            {
                plateNumber = "6" + plateNumber.Substring(1);
            }
            if ((!plateNumber.Contains("NG") && !plateNumber.Contains("NN")) && !plateNumber.Contains("QT"))
            {
                if ((plateNumber.Length == 12) && (plateNumber[9] == '-'))
                {
                    plateNumber = plateNumber.Remove(9, 1);
                }
                else if ((plateNumber.Length == 10) && (plateNumber[7] == '-'))
                {
                    plateNumber = plateNumber.Remove(7, 1);
                }
            }
            plateNumber = plateNumber.Replace("O", "0");
            plateNumber = plateNumber.Replace("W", "M");
            plateNumber = plateNumber.Replace("I", "1");
            plateNumber = this.method_0(plateNumber);
            plateNumber = this.method_1(plateNumber);
            if (this.bool_0)
            {
                plateNumber = this.method_2(plateNumber);
            }
            return plateNumber;
        }

        private string method_0(string string_2)
        {
            if (string_2.Length > 2)
            {
                string str = string_2.Substring(0, 2);
                if (this.string_1 == "60")
                {
                    switch (str)
                    {
                        case "80":
                        case "08":
                        case "00":
                            string_2 = "60" + string_2.Substring(2, string_2.Length - 2);
                            break;
                    }
                    return string_2;
                }
                if (this.string_1 == "68")
                {
                    switch (str)
                    {
                        case "88":
                        case "08":
                        case "00":
                            string_2 = "68" + string_2.Substring(2, string_2.Length - 2);
                            break;
                    }
                    return string_2;
                }
                if (!(this.string_1 == "16"))
                {
                    return string_2;
                }
                switch (str)
                {
                    case "06":
                    case "76":
                    case "46":
                    case "10":
                    case "70":
                    case "96":
                    case "86":
                    case "56":
                    case "50":
                        string_2 = "16" + string_2.Substring(2, string_2.Length - 2);
                        return string_2;

                    case "05":
                    case "75":
                    case "45":
                    case "95":
                        string_2 = "15" + string_2.Substring(2, string_2.Length - 2);
                        break;
                }
            }
            return string_2;
        }

        private string method_1(string string_2)
        {
            if (string_2.Contains("L0"))
            {
                string_2 = string_2.Replace("L0", "LD");
                return string_2;
            }
            if (string_2.Contains("H0"))
            {
                string_2 = string_2.Replace("H0", "HD");
                return string_2;
            }
            if (string_2.Contains("F0"))
            {
                string_2 = string_2.Replace("F0", "FD");
                return string_2;
            }
            char ch = string_2[4];
            if (ch.ToString() == "0")
            {
                string_2 = string_2.Remove(4, 1).Insert(4, "8");
            }
            return string_2;
        }

        private string method_2(string string_2)
        {
            if ((string_2[4] != 'B') && (string_2[4] != 'H'))
            {
                if (string_2[4] == 'Z')
                {
                    string_2 = string_2.Remove(4, 1).Insert(4, "2");
                    return string_2;
                }
                if (string_2[4] == 'S')
                {
                    string_2 = string_2.Remove(4, 1).Insert(4, "5");
                    return string_2;
                }
                if ((string_2[4] != 'T') && (string_2[4] != 'L'))
                {
                    if (string_2[4] == 'F')
                    {
                        string_2 = string_2.Remove(4, 1).Insert(4, "1");
                        return string_2;
                    }
                    if (string_2[4] == 'E')
                    {
                        string_2 = string_2.Remove(4, 1).Insert(4, "6");
                    }
                    return string_2;
                }
                string_2 = string_2.Remove(4, 1).Insert(4, "4");
                return string_2;
            }
            string_2 = string_2.Remove(4, 1).Insert(4, "8");
            return string_2;
        }

        public string CountryCode
        {
            get
            {
                return this.string_0;
            }
            set
            {
                this.string_0 = value;
            }
        }

        public bool EnableMotorUnder50cc
        {
            get
            {
                return this.bool_0;
            }
            set
            {
                this.bool_0 = value;
            }
        }

        public PlateFeatures PlateFeature
        {
            get
            {
                return this.plateFeatures_0;
            }
            set
            {
                this.plateFeatures_0 = value;
            }
        }

        public string ProvinceCode
        {
            get
            {
                return this.string_1;
            }
            set
            {
                this.string_1 = value;
            }
        }
    }
}

